package day01;
import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.sql.Array;
import java.sql.Connection;
import java.util.*;
public class ReviewLessons01 {
    public static void main(String[] args) throws UnsupportedEncodingException {



        /*
        String s = "Hello,World,One,Two,Three,Four,Five ";
        double d = 123.456;
        int i = s.length();
        String s1 = s.trim();
        String s2 = s.toUpperCase();
        String s3 = s.toLowerCase();
        boolean s4 = s.startsWith("Hello");
        boolean s5 = s.endsWith(" ");
        char c = s.charAt(8);
        int s6 = s.indexOf("l");
        int s7 = s.lastIndexOf("e");
        String s8 = s.substring(5);
        String s9 = String.valueOf(d);
        String s10 = "[a-zA-Z]+";
        System.out.println(s.replaceAll("[A-Z]+","*"));
        String[] s11 = s.split("o");
        System.out.println(Arrays.toString(s11));
        System.out.println(s.matches(s10));
        System.out.println(s8);
         */

        /*
        //定时器
        Timer timer = new Timer();
        int ad = 2000;
        timer.schedule(new TimerTask() {
            public void run() {
                System.out.println("该学习了");
            }
        }, ad,ad);
        //找素数 2~100
        for(int num=2;num<=100;num++){
            boolean asd = true;
            for (int i=2;i<=num/2;i++){
                if (num%i==0){
                    asd = false;
                }
            }
            if (asd){
                System.out.println(num+"是素数");
            }else{
                System.out.println(num+"不是素数");
            }
        }
        //数字小游戏
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入数字");
        int num = (int)(Math.random()*1000);
        System.out.println(num);
        while (true){
            int guess = scan.nextInt();
            if (guess>num){
                System.out.println("猜大了");
            }else if (guess<num){
                System.out.println("猜小了");
            }else {
                System.out.println("恭喜你猜对了");
                break;
            }
        }
        //扩容并把最大值放末尾
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*1000);
            System.out.println(arr[i]);
        }
        int max = arr[0];
        for (int i=0;i<arr.length;i++){
            if (max<arr[i]){
                max = arr[i];
            }
        }
        System.out.println("最大值"+max);
        System.out.println("扩容");
        arr = Arrays.copyOf(arr,arr.length+1);
        arr[arr.length-1] = max;
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        //最大值和最小值
        int[] num = new int[10];
        for (int i=0;i<num.length;i++) {
            num[i] = (int) (Math.random() * 1000);
            System.out.println(num[i]);
        }
        int max = num[0];
        int min = num[0];
        for (int i=0;i<num.length;i++){
            if (max<num[i]){
                max = num[i];
            }
            if(min>num[i]){
                min = num[i];
            }
        }
        System.out.println("最大值"+max+"最小值"+min);
        //三角形的*
        for (int i=1;i<=9;i++){
            for (int l=1;l<=i;l++){
                System.out.print("*"+"\t");
            }
            System.out.println();
        }
        //8的乘法表
        for (int max=1;max<=9;max++){
            for (int i=1;i<=max;i++){
                if (max==8){
                    System.out.print(i+"*"+max+"="+i*max+"\t");
                }
            }
            System.out.println();
        }
        //1~100之内偶数的和
        int num = 0;
        for (int i=0;i<=100;i+=2){
            num = num + i;
            System.out.println("偶数的和为:"+num);
        }
        //访问，遍历，最大值
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        System.out.println("求最大值");
        int max = arr[0];
        for (int i=0;i<arr.length;i++){
            if (max<arr[i]){
                max = arr[i];
            }
        }
        //排列
        System.out.println("最大值为:"+max);
        System.out.println("升序");
        Arrays.sort(arr);
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        //99乘法表
        System.out.println("99乘法表")
        for (int i=1;i<=9;i++){
            for (int num=1;num<=i;num++){
                System.out.print(num+"*"+i+"="+num*i+"\t");
            }
            System.out.println();
        }
        //1到100的和
        System.out.println("1+2+3...+99+100的和");
        int i = 1;
        int num = 0;
        while (i<=100){
            num = num+i;
            i++;
        }
        System.out.println("和为:"+num);
        //判断天数  开关
        Scanner scan = new Scanner(System.in);
        System.out.println("判断月的天数");
        System.out.println("请输入年份:");
        int year = scan.nextInt();
        System.out.println("请输入月份:");
        int month = scan.nextInt();
        int days = 0;
        switch(month){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                days = 28;
            default :
                System.out.println("只能输入1~12月份");
        }
        System.out.println(year+"年"+month+"月"+days+"天");
        //输入正负
        System.out.println("输入一个整数判断是否为正负数");
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int a = 0;
        if (num > 0){
            System.out.println("正数");
        }else if(num < 0 ){
            System.out.println("负数");
        }else{
            System.out.println("0");
        }
        //循环5次
        for (int i=1;i<=5;i++){
            System.out.println("你真棒！");
        }
        //猜大小
        Scanner scan = new Scanner(System.in);
        System.out.println("欢迎来到猜大,小环节");
        int num = (int)(Math.random()*1000);
        int num1 = (int)(Math.random()*1000);
        int guess = scan.nextInt();
        while(guess != num){
            if (guess > num){
                System.out.println("猜大了");
            }else{
                System.out.println("猜小了");
            }
            guess = scan.nextInt();
        }
        System.out.println("恭喜你猜对了还有一个");
        while (guess != num1){
            if (guess>num1){
                System.out.println("猜大了");
            }else{
                System.out.println("猜小了");
            }
            guess = scan.nextInt();
        }
        System.out.println("恭喜你全答对了，你真棒");
        //猜大小
        Scanner scan = new Scanner(System.in);
        System.out.println("欢迎来到猜大,小环节");
        int num = (int)(Math.random()*1000);
        int guess1;
        do {
            guess1 = scan.nextInt();
            if (guess1>num){
                System.out.println("猜大了");
            }else if (guess1<num){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜你猜对了");
            }
        }while(guess1 !=num);
        //猜数字
        Scanner scan = new Scanner(System.in);
        System.out.println("欢迎来到数字游戏");
        int score = 0;
        int i = 0;
        while(i<10){
            int a = (int)(Math.random()*100);
            int b = (int)(Math.random()*100);
            int c = a+b;
            i++;
            System.out.println("("+i+")"+a+"+"+b+"=?");
            int guess = scan.nextInt();
            if (c == guess){
                System.out.println("对了");
                score+=10;
            }else{
                System.out.println("错了");
            }
        }
        System.out.println("成绩为:"+score);
        System.out.println("难度升级");
        int score1 = 0;
        int i1 = 0;
        while(i1<10){
            int a1 = (int)(Math.random()*10);
            int b1 = (int)(Math.random()*10);
            int c1 = a1*b1;
            i1++;
            System.out.println("("+i1+")"+a1+"*"+b1+"=?");
            int guess1 = scan.nextInt();
            if (c1 == guess1){
                System.out.println("对了");
                score1+=10;
            }else{
                System.out.println("错了");
            }
        }
        int score2 = score+score1;
        System.out.println("成绩为:"+score2);
        //业务
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入你想办理的业务，1.按摩 2.健身  3.办卡 4.游戏 5.听歌  6.点餐 ");
        int command = scan.nextInt();
        switch(command){
            case 1:
                System.out.println("按摩:1.泡脚 2.拔罐 3.刮痧");
                break;
            case 2:
                System.out.println("健身:1.跑步 2.跳绳 3.游泳");
                break;
            case 3:
                System.out.println("办卡:1.钻石卡 2. 白金卡 3.黄金卡");
                break;
            case 4:
                System.out.println("游戏:1.王者荣耀 2.和平精英 3.英雄联盟");
                break;
            case 5:
                System.out.println("听歌:1.成都");
                break;
            case 6:
                System.out.println("点餐:1.肯德基 2.季季红 3.奶茶");
                break;
            default:
                System.out.println("请按1~6，谢谢");
        }
        //年份
        System.out.println("请输入你想知道的年份，比如2000，2020，判断是否为闰年或平年");
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int year = a;
        if (year%4==0&&year%100!=0||year%400==0){
            System.out.println(year+"是闰年");
        }else{
            System.out.println(year+"是平年");
        }
        //成绩
        int score = 80;
        if (score<0 || score>100){
            System.out.println("成绩不合法");
        }else if(score>=90){
            System.out.println("成绩优");
        }else if (score>=80&&score<90){
            System.out.println("成绩良");
        }else if (score>=60&&score<80){
            System.out.println("成绩一般");
        }else{
            System.out.println("成绩不及格");
        }
        //找最大数
        int a = 6,b = 2;
        int max = 0;
        if (a>b){
            max = a;
        }else{
            max = b;
        }
        System.out.println("最大的数为:"+max);
         */
    }
    /*
     public static void main(String[] args) {
        //验证码
        String code = generateVeriCode(6);
        System.out.println("验证码:"+code);
    }
    public static String generateVeriCode(int len){
        String code = "";
        char[] chs = {'a','b','c','d','e','f','g','h','i','j','k', 'l','m','n',
                'o','p','q','r','s','t','u','v', 'w','x','y','z','A','B','C','D',
                'E','F','G', 'H','I','J','K','L','M','N','O','P','Q','R', 'S','T',
                'U','V','W','X','Y','Z','0','1','2', '3','4','5','6','7','8','9'};
        Random rand = new Random();
        for (int i=1;i<=len;i++){
            int index = rand.nextInt(chs.length);
            code += chs[index];
        }
        return code;
    }
    public static void main(String[] args) {
        //6位评委打分
        System.out.println("请评委们打分");
        double[] score = enterData();
        double avg = calAvg(score);
        System.out.println(avg);
    }
    public static double[] enterData(){
        Scanner scan = new Scanner(System.in);
        double[] score = new double[6];
        for (int i=0;i<score.length;i++){
            System.out.println("请输入第"+(i+1)+"个评委的分数:");
            score[i] = scan.nextDouble();
        }
        return score;
    }
    public static double calTotal(double[] score){
        double total= 0;
        double max = score[0];
        double min = score[0];
        for (int i=0;i<score.length;i++){
            total+=score[i];
            if (max<score[i]){
                max = score[i];
            }
            if (min>score[i]){
                min = score[i];
            }
        }
        return total-max-min;
    }
    public static double calAvg(double[] score){
        double total = calTotal(score);
        double avg = total/(score.length-2);
        return avg;
    }
    public static void main(String[] args) {
        //机票价格
        Scanner scan = new Scanner(System.in);
        System.out.println("输入机票原价");
        double price = scan.nextDouble();
        System.out.println("输入你要的月份");
        int month = scan.nextInt();
        System.out.println("输入你要的舱位:1.头等舱 2.商务舱 3.经济舱");
        int type = scan.nextInt();

        double a = lajs(price,month,type);
        System.out.println(a);
    }
    public static double lajs(double price,int month,int type){
        double finalPrice = 0.0;
        if (month<1||month>12){
            System.out.println("你请输入的月份有错");
            return -1;
        }
        if(type<1||type>3){
            System.out.println("你输入的舱位有错");
            return -1;
        }
        if (month>=5&&month<=10){
            switch (type){
                case 1:
                    finalPrice = price*0.9;
                    break;
                case 2:
                    finalPrice = price*0.85;
                    break;
                case 3:
                    finalPrice = price*0.8;
                    break;
                default:
                    System.out.println("输入有误");
            }
        }else{
            switch(type){
                case 1:
                    finalPrice = price*0.7;
                    break;
                case 2:
                    finalPrice = price*0.65;
                    break;
                case 3:
                    finalPrice = price*0.6;
                    break;
                default:
                    System.out.println("输入有误");
            }

        }
        return finalPrice;
    }
    public static void main(String[] args) {
        //调用方法实现最大值
        int[] arr = {60,90,2,36,66,9,33};
        int max = geMaxOfArray(arr);
        System.out.println("最大值"+max);

        int[] num = new int[10];
        for (int i=0;i<num.length;i++){
            num[i] = (int)(Math.random()*100);
            System.out.println(num[i]);
        }
        int max1 = geMaxOfArray(num);
        System.out.println("最大值"+max1);
    }
    public static int geMaxOfArray(int[] arr){
        int max = arr[0];
        for (int i=0;i<arr.length;i++){
            if (max<arr[i]){
                max = arr[i];
            }
        }
        return max;
    }

    public static void main(String[] args) {
        //方法的调用
        say();
        sayHi("小何");
        saHello("小何", 3);
        int num = getNum();
        System.out.println(num);
        int num1 = plus(3, 5);
        System.out.println(num1);
        int[] num2 = tesArray(10, 300);
        for (int i = 0; i < num2.length; i++) {
            System.out.println(num2[i]);
        }
    }
    public static void say(){}
    public static void sayHi(String name){
        System.out.println("大家好我叫"+name);
    }
    public static void saHello(String name,int age){
        System.out.println("大家好我叫"+name+"今年"+age+"岁了");
    }
    public static int getNum(){
        return 3;
    }
    public static int plus(int num1,int num2){
        int num = num1+num2;
        return num;
    }
    public static int[] tesArray(int len,int max){
        int[] arr = new int[len];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*(max+1));
        }
        return arr;
    }
     */
}

/*
//动物 超类
public static void main(String[] args) {
        //抽象，接口，继承，实现
        Animal[] animal = new Animal[10];
        animal[7] = new Dog("小黑",3,"黑");
        animal[1] = new Dog("小白",2,"白");
        animal[6] = new Dog("小蓝",6,"蓝");
        animal[3] = new Dog("小灰",3,"灰");
        animal[8] = new Chick("小花",4,"花");
        animal[5] = new Chick("小红",1,"红");
        animal[9] = new Fish("小金",2,"金");
        animal[2] = new Fish("小粉",5,"粉");
        animal[0] = new Fish("小美",3,"美");
        animal[4] = new Fish("小绿",2,"绿");
        for (int i=0;i<animal.length;i++){
            System.out.println(animal[i].name);
            animal[i].eat();
            animal[i].drink();
            if (animal[i] instanceof Dog){
                Dog dog = (Dog)animal[i];
                dog.lookHome();
            }
            if (animal[i] instanceof Chick){
                Chick chick = (Chick) animal[i];
                chick.layEggs();
            }
            if (animal[i] instanceof Swim){
                Swim swim = (Swim)animal[i];
                swim.swim();
            }
        }
    }
abstract class Animal {
    String name;
    int age;
    String color;
    Animal(String name,int age,String color){
        this.name = name;
        this.age = age;
        this.color = color;
    }
    void drink(){
        System.out.println(color+"色的"+age+"岁的"+name+"正在喝水...");
    }
    abstract void eat();
}
//接口
interface Swim{
    void swim();
}
//狗狗
class Dog extends Animal implements Swim{
    Dog(String name,int age,String color){
        super(name,age,color);
    }
    void lookHome(){
        System.out.println(color+"色的"+age+"岁的小狗"+name+"正在看家...");
    }
    void eat(){
        System.out.println(color+"色的"+age+"岁的小狗"+name+"正在啃骨头...");
    }
    public void swim(){
        System.out.println(color+"色的"+age+"岁的小狗"+name+"正在游泳...");
    }
}
//小鸡
class Chick extends Animal{
    Chick(String name,int age,String color){
        super(name,age,color);
    }
    void layEggs(){
        System.out.println(color+"色的"+age+"岁的小鸡"+name+"正在下蛋...");
    }
    void eat(){
        System.out.println(color+"色的"+age+"岁的小鸡"+name+"正在吃小米...");
    }
}
//小鱼
class Fish extends Animal implements Swim{
    Fish(String name,int age,String color){
        super(name,age,color);
    }
    void eat(){
        System.out.println(color+"色的"+age+"岁的小鱼"+name+"正在吃小虾...");
    }
    public void swim(){
        System.out.println(color+"色的"+age+"岁的小鱼"+name+"正在游泳...");
    }
}
 */
